package lib

func init() {
	Probs = append(Probs, Problem{
		Num:         50,
		Discription: "Pow(x,n)",
		Level:       2,
		Labels: map[string]int{
			"递归": 1,
		},
	})
}

func MyPow(x float64, n int) float64 {
	if n == 0 {
		return 1
	}

	//注意n的正负
	if n == 1 {
		return x
	}

	if n == -1 {
		return float64(1) / x
	}

	//注意n的奇偶
	temp := MyPow(x, n/2)
	overflow := n % 2
	return temp * temp * MyPow(x, overflow)
}
